<?php

namespace App\Http\Controllers\Manage;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EyeController extends Controller
{
    public function index()
    {
        $user = \Auth::user();

        if ($user->isAdmin()) {
            $hospitals = \App\Models\Hospital::hasDoctors()->select(['id', 'name'])->get();
            $doctors   = $hospitals->first()->doctors(['id', 'name'])->getResults();
        } elseif ($user->isDoctorsAdmin()) {

            $hospitals = $user->hospital()->select(['id', 'name'])->first();
            $doctors   = $hospitals->doctors(['id', 'name'])->getResults();
        } else {

            $hospitals = $user->hospital()->select(['id', 'name'])->get();
            $doctors   = $user;
        }

        $city    = new \App\Models\City();
        $address = $city->beforeLinkage();

        return view('manage.eyeground', compact('hospitals', 'doctors', 'address'));
    }
}
